<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function myfn(color){
		var d = document.getElementById("d1");
		d.innerHTML+="<div class='"+color+"'></div>";
	}
</script>
<style type="text/css">
	.red{
		width: 50px;
		height: 50px;
		background-color: red;
		margin: 5px;
	}
	
	.blue{
	width: 50px;
	height: 50px;
	background-color:blue;
	margin: 5px;
}
</style>
</head>
<body>
<div id="d1"></div>
<input type="button" value="红" onclick="myfn('red')">
<input type="button" value="蓝" onclick="myfn('blue')">
</body>
</html>